﻿/*******************************************************************************
Copyright (c) 2011-2013, PKStudio

http://pkstudio.org

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/

using System;
using System.Drawing;

namespace PKEngine
{
	/// <summary>
	/// Alpha BitBlt.
	/// </summary>
	public abstract class PKAlpha
	{
		#region Singleton
		private static PKAlpha _sharedAlpha;

		public static PKAlpha SharedAlpha
		{
			get
			{
				if (_sharedAlpha == null)
				{
					if (PKConfig.SharedConfig.PixelFormat == PKPixelFormat.Argb1555)
					{
						_sharedAlpha = new PKAlphaForArgb1555();
					}
					else if (PKConfig.SharedConfig.PixelFormat == PKPixelFormat.Rgb565)
					{
						_sharedAlpha = new PKAlphaForRgb565();
					}
					else if (PKConfig.SharedConfig.PixelFormat == PKPixelFormat.Rgb555)
					{
						_sharedAlpha = new PKAlphaForRgb555();
					}
					else if (PKConfig.SharedConfig.PixelFormat == PKPixelFormat.Argb4444)
					{
						_sharedAlpha = new PKAlphaForArgb4444();
					}
				}
				return _sharedAlpha;
			}
		}
		#endregion

		#region Public Properties
		public abstract ushort ColorKey { get; }
		public abstract ushort ColorBlack { get; }
		public abstract ushort ColorWhite { get; }
		public abstract ushort ColorRed { get; }
		public abstract ushort ColorGreen { get; }
		public abstract ushort ColorBlue { get; }
		#endregion

		#region Public Methods
		public abstract ushort ColorFromRgb(int red, int green, int blue);
		public abstract ushort ColorFromRgba(int red, int green, int blue, int alpha);
		public abstract int RedOfColor(ushort color);
		public abstract int GreenOfColor(ushort color);
		public abstract int BlueOfColor(ushort color);
		public abstract int AlphaOfColor(ushort color);

		public abstract void DrawLine(PKSurface dSurface, Point dPoint1, Point dPoint2, ushort color);
		public abstract void DrawRectangle(PKSurface dSurface, Rectangle dRect, ushort color);
		public abstract void Fill(PKSurface dSurface, Rectangle dRect, ushort color);
		public abstract void FillAlpha(PKSurface dSurface, Rectangle dRect, ushort color, int alpha);
		public abstract void FillWithAlphaChannel(PKSurface dSurface, int dX, int dY, PKChannel sChannel, Rectangle sRect, ushort color);

		public abstract void Blt(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect);
		public abstract void BltStretch(PKSurface dSurface, Rectangle dRect, PKSurface sSurface, Rectangle sRect);
		public abstract void BltAlpha(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect, int alpha);
		public abstract void BltAlphaStretch(PKSurface dSurface, Rectangle dRect, PKSurface sSurface, Rectangle sRect, int alpha);
		public abstract void BltAdd(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect);
		public abstract void BltSub(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect);
		public abstract void BltGray(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect);
		public abstract void BltHue(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect, int hue);
		public abstract void BltTint(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect, ushort color, int colorAlpha);
		public abstract void BltColor(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect, ushort color);
		public abstract void BltWithTransitionChannel(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect, PKChannel channel, int value);
		public abstract void BltWithAlphaChannel(PKSurface dSurface, int dX, int dY, PKSurface sSurface, Rectangle sRect, PKChannel channel);

		public abstract ushort PixelAlpha(ushort dColor, ushort sColor, int alpha);
		#endregion
	}
}
